package com.example.rjb_shoping.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.io.Serializable;
import java.util.List;

/**
 * (RjbAdmin)实体类
 *
 * @author makejava
 * @since 2021-06-09 20:42:18
 */
@ToString
@Data
public class RjbAdmin implements Serializable, UserDetails {
    private static final long serialVersionUID = 553343420856353299L;

    private Integer aId;

    private String username;

    private String password;

    private String aNickname;

    private String aSex;

    private String aImg;

    private String aPhone;

    private String aEmai;

    private String aDepartment;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date aCreate;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date aEnd;

    private String aEmailStatus;

    private Integer aStatus;

    private List<RjbRule> roles;

    /**
     * 获取权限方法
     * @return
     */
    @JSONField(serialize = false)
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(roles == null || roles.size()<=0){
            return null;
        }
        List<GrantedAuthority> authorities = new ArrayList<>();
        for(RjbRule role:roles){
            authorities.add(role);
        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }
    @JSONField(serialize = false)
    //true：账号未过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JSONField(serialize = false)
    //true：账号未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    @JSONField(serialize = false)
    //true：凭证未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    @JSONField(serialize = false)
    //true：账号可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
